package com.guonl.model;

import java.util.ArrayList;
import java.util.Arrays;

public class Country {
    private Integer serialNo;

    private String nameEn;

    private String nameZh;

    private String twoShortNameEn;

    private String threeShortNameEn;

    private String phoneCode;

    public Integer getSerialNo() {
        return serialNo;
    }

    public void setSerialNo(Integer serialNo) {
        this.serialNo = serialNo;
    }

    public String getNameEn() {
        return nameEn;
    }

    public void setNameEn(String nameEn) {
        this.nameEn = nameEn == null ? null : nameEn.trim();
    }

    public String getNameZh() {
        return nameZh;
    }

    public void setNameZh(String nameZh) {
        this.nameZh = nameZh == null ? null : nameZh.trim();
    }

    public String getTwoShortNameEn() {
        return twoShortNameEn;
    }

    public void setTwoShortNameEn(String twoShortNameEn) {
        this.twoShortNameEn = twoShortNameEn == null ? null : twoShortNameEn.trim();
    }

    public String getThreeShortNameEn() {
        return threeShortNameEn;
    }

    public void setThreeShortNameEn(String threeShortNameEn) {
        this.threeShortNameEn = threeShortNameEn == null ? null : threeShortNameEn.trim();
    }

    public String getPhoneCode() {
        return phoneCode;
    }

    public void setPhoneCode(String phoneCode) {
        this.phoneCode = phoneCode == null ? null : phoneCode.trim();
    }

    public static Country.Builder builder() {
        return new Country.Builder();
    }

    public static class Builder {
        private Country obj;

        public Builder() {
            this.obj = new Country();
        }

        public Builder serialNo(Integer serialNo) {
            obj.setSerialNo(serialNo);
            return this;
        }

        public Builder nameEn(String nameEn) {
            obj.setNameEn(nameEn);
            return this;
        }

        public Builder nameZh(String nameZh) {
            obj.setNameZh(nameZh);
            return this;
        }

        public Builder twoShortNameEn(String twoShortNameEn) {
            obj.setTwoShortNameEn(twoShortNameEn);
            return this;
        }

        public Builder threeShortNameEn(String threeShortNameEn) {
            obj.setThreeShortNameEn(threeShortNameEn);
            return this;
        }

        public Builder phoneCode(String phoneCode) {
            obj.setPhoneCode(phoneCode);
            return this;
        }

        public Country build() {
            return this.obj;
        }
    }

    public enum Column {
        serialNo("serial_no", "serialNo", "INTEGER", false),
        nameEn("name_en", "nameEn", "VARCHAR", false),
        nameZh("name_zh", "nameZh", "VARCHAR", false),
        twoShortNameEn("two_short_name_en", "twoShortNameEn", "VARCHAR", false),
        threeShortNameEn("three_short_name_en", "threeShortNameEn", "VARCHAR", false),
        phoneCode("phone_code", "phoneCode", "VARCHAR", false);

        private static final String BEGINNING_DELIMITER = "\"";

        private static final String ENDING_DELIMITER = "\"";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public static Column[] all() {
            return Column.values();
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}